"use strict";
cc._RF.push(module, '2dba3QbYHRGUK8BhapNZSww', 'DFightViewUI');
// scripts/DFightViewUI.js

"use strict";

var e = require;
var t = module;
var o = exports;

var _ii,
    nn = void 0 && (void 0).__extends || (_ii = function ii(t, e) {
  return (_ii = Object.setPrototypeOf || {
    __proto__: []
  } instanceof Array && function (t, e) {
    t.__proto__ = e;
  } || function (t, e) {
    for (var o in e) {
      Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o]);
    }
  })(t, e);
}, function (t, e) {
  function o() {
    this.constructor = t;
  }

  _ii(t, e), t.prototype = null === e ? Object.create(e) : (o.prototype = e.prototype, new o());
}),
    rr = void 0 && (void 0).__awaiter || function (t, e, o, i) {
  return new (o || (o = Promise))(function (n, a) {
    function r(t) {
      try {
        l(i.next(t));
      } catch (e) {
        a(e);
      }
    }

    function s(t) {
      try {
        l(i["throw"](t));
      } catch (e) {
        a(e);
      }
    }

    function l(t) {
      var e;
      t.done ? n(t.value) : (e = t.value, e instanceof o ? e : new o(function (t) {
        t(e);
      })).then(r, s);
    }

    l((i = i.apply(t, e || [])).next());
  });
};

var oo = void 0 && (void 0).__decorate || function (e, t, a, n) {
  var i,
      o = arguments.length,
      s = o < 3 ? t : null === n ? n = Object.getOwnPropertyDescriptor(t, a) : n;
  if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) s = Reflect.decorate(e, t, a, n);else for (var r = e.length - 1; r >= 0; r--) {
    (i = e[r]) && (s = (o < 3 ? i(s) : o > 3 ? i(t, a, s) : i(t, a)) || s);
  }
  return o > 3 && s && Object.defineProperty(t, a, s), s;
};

Object.defineProperty(o, "__esModule", {
  value: !0
});

var a = e("BaseModuleUI"),
    n = e("NotifyEventType"),
    i = e("GlobalParams"),
    r = e("AssetsManager"),
    s = e("AudioManager"),
    l = e("ArrayUtil"),
    _ = e("CommonHelper"),
    c = e("Game"),
    d = e("RoleSoldierInfo"),
    h = e("BuyEquipInfo"),
    u = e("node_team"),
    p = e("role_node"),
    m = e("AD"),
    f = e("d_monster_item"),
    v = e("equip_ball_anime"),
    g = cc._decorator,
    y = g.ccclass,
    I = g.property,
    w = function (e) {
  function t() {
    var t = null !== e && e.apply(this, arguments) || this;
    return t.map_sprite = null, t.player_view_ui = null, t.player_info_tip_view = null, t.count_down_time = null, t.map_name_sprite = null, t.game_over_anime = null, t.monster_index = 0, t.hero_start_pos = [cc.v2(-700, -170), cc.v2(-800, -50), cc.v2(-800, -300)], t.monster_start_pos = [[cc.v2(-1e3, -170), cc.v2(-1e3, -50), cc.v2(-1e3, -300), cc.v2(1e3, -170), cc.v2(1e3, -50), cc.v2(1e3, -300)], [cc.v2(-1e3, -150), cc.v2(-1e3, -280), cc.v2(1e3, -150), cc.v2(1e3, -280)], [cc.v2(-1e3, -100), cc.v2(1e3, -100)], [cc.v2(700, -170), cc.v2(900, -50), cc.v2(900, -300)]], t.have_monseter_number = 0, t.hero_node_list = [], t.random_get_equip = [], t;
  }

  return nn(t, e), t.prototype.initView = function () {
    s["default"].getInstance().setMusicVolume(1), i.GlobalParams.gameMusicName = "d_bgm", s["default"].playGameBGM(), i.GlobalParams.ChangeGameMode = 0, this.monster_index = 0, i.GlobalParams.MatchMyIndex = 0, i.GlobalParams.GamePlayerInfo = [], i.GlobalParams.BuyEquipInfo = [], this.random_get_equip = this.random_get_equip.concat(c["default"].equip_ball_list), this.random_get_equip = l["default"].fisherYatesShuffle(this.random_get_equip), this.game_over_anime.node.parent.active = !1, i.GlobalParams.GameStart = !1, i.GlobalParams.DHeroEquipInfo = {
      get_equip: [],
      hero_equip: [[-1, -1, -1], [-1, -1, -1], [-1, -1, -1]]
    }, this.showGameBegin();
  }, t.prototype.addEvent = function () {
    this.attachEvent(n["default"].SEND_GAME_OVER_INFO, this.showGameOver, this), this.attachEvent(n["default"].SEND_MONSTER_DIE_NUMBER_INFO, this.showMonsterDie, this), this.attachEvent(n["default"].SEND_CONTINUE_D_FIGHT_GAME, this.showGameBegin, this);
  }, t.prototype.showGameBegin = function () {
    var e = this;
    this.setGamePlayerInfo(), this.map_sprite.spriteFrame = r["default"].getInstance().getTexture2DSprite("bg_0" + (this.monster_index + 1)), this.map_name_sprite.spriteFrame = r["default"].getInstance().getTexture2DSprite("map_name_" + (this.monster_index + 1)), this.map_name_sprite.node.parent.scale = 0, cc.tween(this.map_name_sprite.node.parent).to(0.3, {
      scale: 1
    }).start(), this.CreateHeroInfo(), this.monster_index < 3 ? this.CreateMonster() : this.CreateAiHeroInfo(), this.emitEvent(n["default"].SEND_D_GAME_TOUCH_OPERATE_INFO), this.count_down_time.node.parent.active = !0, this.count_down_time.setAnimation(0, "djs", !1), s["default"].getInstance().playFx("count_down"), this.count_down_time.setCompleteListener(function () {
      e.count_down_time.setCompleteListener(null), i.GlobalParams.GameStart = !0, e.count_down_time.node.parent.active = !1;
    });
  }, t.prototype.showMonsterDie = function (e, t) {
    var o = this;
    this.have_monseter_number--, this.have_monseter_number <= 0 && (i.GlobalParams.GameStart = !1, this.monster_index++, this.monster_index > 3 ? (i.GlobalParams.GamePlayerWin = !0, this.scheduleOnce(function () {
      o.showGameOver(), cc.log("========游戏胜利=========");
    }, 2)) : (i.GlobalParams.DarePlayerInfo[0].schedule = this.monster_index, this.scheduleOnce(function () {
      var e = _["default"].getRandomInt(2, 3);

      i.GlobalParams.DHeroEquipInfo.get_equip = [], o.player_view_ui.getComponent(v["default"]).showEquipAnime(e, t);

      for (var a = 0; a < e; a++) {
        var n = _["default"].getRandomInt(0, o.random_get_equip.length - 1),
            s = o.random_get_equip[n];

        o.random_get_equip.splice(n, 1), i.GlobalParams.DHeroEquipInfo.get_equip.push(s);
      }

      o.scheduleOnce(function () {
        cc.find("Canvas").addChild(cc.instantiate(r["default"].getInstance().getFightPrefab("ChooseEquipViewUI")));
      }, 2);
    }, 1)));
  }, t.prototype.CreateMonster = function () {
    var e = this.monster_start_pos[this.monster_index];
    this.have_monseter_number = e.length;

    for (var t = 0; t < e.length; t++) {
      var o;
      o = 0 == this.monster_index ? t < 3 ? "monster_0_0" : "monster_0_1" : "monster_" + this.monster_index;
      var a = r["default"].getInstance().getFightPrefab(o),
          n = cc.instantiate(a);
      n.setPosition(e[t]), n.getComponent(f["default"]).showMonsterIndex(t, this.monster_index), n.getComponent(u["default"]).setTeamInfo(c.TeamInfo.right_team), n.scaleX = e[t].x < 0 ? -1 : 1, this.player_view_ui.addChild(n);
    }
  }, t.prototype.CreateHeroInfo = function () {
    this.hero_node_list = [], this.player_view_ui.destroyAllChildren(), this.player_info_tip_view.destroyAllChildren();

    for (var e = 0; e < 3; e++) {
      this.creationRole(e);
    }
  }, t.prototype.creationRole = function (e) {
    var t = i.GlobalParams.MatchGamePlayer[e].role_id;

    if (!(t < 0)) {
      var o = r["default"].getInstance().getFightPrefab("role_" + t),
          a = cc.instantiate(o);
      a.name = "role_" + e, a.getComponent(p["default"]).showRoleInfo(e != i.GlobalParams.MatchMyIndex, e, !(this.monster_index < 3)), a.getComponent(u["default"]).setTeamInfo(c.TeamInfo.left_team), a.setPosition(this.hero_start_pos[e]), a.scaleX = -1;
      var n = cc.instantiate(r["default"].getInstance().getFightPrefab("player_info_node"));
      n.zIndex = e == i.GlobalParams.MatchMyIndex ? 7 : e, a.getComponent(p["default"]).setPlayerInfoNode(n), n.setParent(this.player_info_tip_view), this.player_view_ui.addChild(a), this.hero_node_list.push(a);
    }
  }, t.prototype.CreateAiHeroInfo = function () {
    this.have_monseter_number = 3;

    for (var e = 3; e < 6; e++) {
      var t = i.GlobalParams.MatchGamePlayer[e].role_id;
      if (t < 0) return;
      var o = r["default"].getInstance().getFightPrefab("role_" + t),
          a = cc.instantiate(o);
      a.name = "role_" + e, a.getComponent(p["default"]).showRoleInfo(e != i.GlobalParams.MatchMyIndex, e, !0), a.getComponent(u["default"]).setTeamInfo(c.TeamInfo.right_team), a.setPosition(this.monster_start_pos[this.monster_index][e - 3]), a.scaleX = 1;
      var n = cc.instantiate(r["default"].getInstance().getFightPrefab("player_info_node"));
      n.zIndex = e == i.GlobalParams.MatchMyIndex ? 7 : e, a.getComponent(p["default"]).setPlayerInfoNode(n), n.setParent(this.player_info_tip_view), this.player_view_ui.addChild(a);
    }
  }, t.prototype.heroStartPosInit = function () {
    for (var e = 0; e < 3; e++) {
      var t = this.hero_node_list[e];
      t && cc.isValid(t, !0) && (t.setPosition(this.hero_start_pos[e]), t.scaleX = -1);
    }
  }, t.prototype.setGamePlayerInfo = function () {
    i.GlobalParams.GamePlayerInfo = [], h["default"].buyEquipInit();

    for (var e = 0; e < 6; e++) {
      var t = i.GlobalParams.MatchGamePlayer[e],
          o = h["default"].getPlayerInit();

      if (-1 != t.role_id) {
        var a = d["default"].Role_info[t.role_id];
        o.attack = a.C_attack + 10 * a.C_attack_up, o.skill_1 = Math.floor(a.S1_attack + 5 * (a.C_attack * a.S1_attack_add + a.S1_attack_up)), o.skill_2 = Math.floor(a.S2_attack + 5 * (a.C_attack * a.S2_attack_add + a.S2_attack_up)), o.skill_3 = Math.floor(a.S3_attack + 5 * (a.C_attack * a.S3_attack_add + a.S3_attack_up)), o.hp = a.C_hp + 10 * a.C_hp_up, o.move_speed = 30, o.attack_speed = 1, o.cool_1 = d["default"].Hore_Skill_Info[t.role_id].one_time, o.cool_2 = d["default"].Hore_Skill_Info[t.role_id].two_time, o.cool_3 = d["default"].Hore_Skill_Info[t.role_id].three_time;
      }

      i.GlobalParams.GamePlayerInfo.push(o), h["default"].playerBuyEquipInfo(e, function () {});
    }

    cc.log(i.GlobalParams.GamePlayerInfo);
  }, t.prototype.showGameOver = function () {
    s["default"].getInstance().playFx(i.GlobalParams.GamePlayerWin ? "victory" : "defeat"), this.game_over_anime.node.parent.active = !0, this.game_over_anime.setAnimation(0, i.GlobalParams.GamePlayerWin ? "sl" : "sb", !1), i.GlobalParams.gameShock.value && m["default"].getInstance().vibrateShort(), this.scheduleOnce(function () {
      cc.find("Canvas").addChild(cc.instantiate(r["default"].getInstance().getFightPrefab("GameOverViewUI")));
    }, 3);
  }, oo([I(cc.Sprite)], t.prototype, "map_sprite", void 0), oo([I(cc.Node)], t.prototype, "player_view_ui", void 0), oo([I(cc.Node)], t.prototype, "player_info_tip_view", void 0), oo([I(sp.Skeleton)], t.prototype, "count_down_time", void 0), oo([I(cc.Sprite)], t.prototype, "map_name_sprite", void 0), oo([I(sp.Skeleton)], t.prototype, "game_over_anime", void 0), oo([y], t);
}(a["default"]);

o["default"] = w;

cc._RF.pop();